package com.huluobo.higt4demo1911.core.http.base;

/**
 * Created by lc on 2022/4/19.
 * 网络请求单例工厂
 * 单例 关键点:***私有化构造函数***
 * 单例可以使用synchronized 控制线程,在外部调用时可以保证线程安全
 */
public class HttpFactory implements IFactory {

    private static HttpFactory factory;

    public static HttpFactory getInstance() {
        if (factory == null) {
            factory = new HttpFactory();
        }
        return factory;
    }

    private NetWorkProductImpl netWorkProduct;
    private FileProductImpl fileProduct;

    @Override
    public IProduct create(ProductType type) {
        switch (type) {
            default:
            case NETWORK:
                if (netWorkProduct == null) {
                    netWorkProduct = new NetWorkProductImpl();
                }
                return netWorkProduct;
            case FILE:
                if (fileProduct == null) {
                    fileProduct = new FileProductImpl();
                }
                return fileProduct;
        }
    }
}
